	var manager, g;
	function f_initGrid(dataUrl, postParams)
	{ 
		g = manager = $("#maingrid").ligerGrid({
			columns: [
			{ display: '型号',  name: 'xh',editor: { type: 'text' }},
			{ display: '数量',  name: 'sl',editor: { type: 'text' }},
			{ display: '单价', name: 'dj',editor: { type: 'text' }},
			{ display: '销售类型（批发/零售）',  name: 'xslx',editor: { type: 'text' }}
			],
			toolbar: { items: [
			                    { text: '增加', click: itemclick, icon: 'add' },
			                    { line: true },
			                    { text: '修改', click: itemclick, icon: 'modify' },
			                    { line: true },
			                    { text: '删除', click: itemclick, icon: 'delete' }
			                  ]
			         },

			enabledEdit: false, height: '95%', checkbox:true,rownumbers:true,
			parms:postParams,
			url :dataUrl,
			width: '100%'
		});   
	}
	
	
	function itemclick(item) {
		if(!$("#ddId").val()) {
			$.ligerDialog.warn('必须先填写并保存订单信息！');
			return;
		}
		var dataVal = {ddId: $("#ddId").val(),
				ddh: $("#ddh").val()};
		if(item.text == '修改') {
			var row = getSelected();
			if(!row) return;
			dataVal.ddxxId = row.id;
			dataVal.xh = row.xh;
			dataVal.sl = row.sl;
			dataVal.dj = row.dj;
			dataVal.xslx = row.xslx;
			openDialog(item.text, dataVal);
		} else if(item.text == '增加') {
			openDialog(item.text, dataVal);
		} else if(item.text == '删除'){
			deleteDdxxxx();
		}
	}
	
	function deleteDdxxxx() {
		var row = manager.getSelectedRows();
		if (!row.length) { 
			$.ligerDialog.warn('请选择一条数据！');
		}else{
			if(confirm("当前选择了["+ row.length +"]条数据! \n请确认是否删除这些数据！")){
				var url = contextPath + "/DdglAction?control=deleteDdxxxx&id=";
				var id = "";
				for(var i =0;i<row.length;i++){
					if(i==(row.length-1)){
						id += row[i].id;
					}else{
						id += row[i].id+ "-";
					}
					
				}
				url += id;
				sendAjaxRequest(url, null, false,function(msg) {
					if(msg.data == "删除成功") {
						$.ligerDialog.success("删除成功");
						manager.reload();
					} else {
						$.ligerDialog.error(msg.data);
					}
				});
			}
		}
	}
	
	function openDialog(title, dataVal) {
		$.ligerDialog.open({
			height:300,
			width: 600,
			title : title,
			url: contextPath + '/jsp/ddxx_xz.jsp',
			showMax: false,
			showToggle: true,
			showMin: false,
			isResize: true,
			slide: false,
			name:'ligeruiWindow',
			isHidden: false,
			data: dataVal
		});
	}
	
	function getSelected()
	{ 
		var row = manager.getSelectedRow();
		if (!row) { 
			$.ligerDialog.warn('请选择行');
			return; 
		}
		
		return row;
	}
	function getData()
	{ 
		return manager.getData();
	} 
	
	function reloadData() {
		manager.reload();
	}